#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_set>
using namespace std;

class Solution{
    public:
    bool ans1(string pattern, string s){
        unordered_map<char, string> map1;
        unordered_map<string, char> map2;
        vector<string> str;
        string comp1 = "";
        string comp2 = "";
        int len1 = pattern.size();
        int len2 = s.size();

        int i = 0;
        for(int j = 0; j != len1; j++){
            string temp = "";
            
            while(true){
                if(s[i] == ' '){
                    i++;
                    break;
                }
                if(i == len2){
                    break;
                }
                temp = temp + s[i];
                i++;
            }
            map1[pattern[j]] = temp;
            map2[temp] = pattern[j];
            str.push_back(temp);
        }

        for(int i = 0; i != len1-1; i++){
            comp1 = comp1 + map1[pattern[i]] + " ";
            comp2 = comp2 + map2[str[i]];
        }
        comp1 = comp1 + map1[pattern[len1-1]];
        comp2 = comp2 + map2[str[len1-1]];
        int ret1 = comp1.compare(s);
        int ret2 = comp2.compare(pattern);
        if(ret1 == 0 && ret2 == 0){
            return true;
        }else{
            return false;
        }
    }
};

void test1(){
    Solution s;
    string str1 = "abba";
    string str2 = "dog cat cat dog";
    bool ret = s.ans1(str1, str2);
    cout << ret << endl;
}

void test2(){
    Solution s;
    string str1 = "abba";
    string str2 = "dog cat cat fish";
    bool ret = s.ans1(str1, str2);
    cout << ret << endl;
}

void test3(){
    Solution s;
    string str1 = "aaaa";
    string str2 = "dog cat cat dog";
    bool ret = s.ans1(str1, str2);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();
    test3();

    return 0;
}